﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PiaoanWeb.AppLogic.BusinessLogicLayer;
using PiaoanWeb.AppLogic.DataAccessLayer;
using PiaoanWeb.Helpers;
namespace PiaoanWeb.Admin
{
    public partial class ProductCategory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CategoriesBLL categoriesBLL = new CategoriesBLL();
                CategoryListGridView.DataSource = categoriesBLL.GetAllCategoriesExcludeDeleted();
                CategoryListGridView.DataBind();
            }
        }

        protected void addCategoryBtn_Click(object sender, EventArgs e)
        {
            try
            {
                CategoriesBLL categoriesBLL = new CategoriesBLL();
                Categories category = new Categories();
                category.Name = categoryNameTxtBox.Text;
                category.IsActive = true;
                categoriesBLL.AddCategory(category);

                Response.Redirect("AddProduct.aspx");
                //CategoryListGridView.DataSource = categoriesBLL.GetAllCategoriesExcludeDeleted();
                //CategoryListGridView.DataBind();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }

        protected void CategoryListGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label indexLbl = e.Row.FindControl("indexLbl") as Label;
                indexLbl.Text = (e.Row.RowIndex + 1).ToString();
            }
        }
    }
}